package com.smm.util;

import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwk.UrlJwkProvider;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.SignatureGenerationException;
import com.auth0.jwt.exceptions.SignatureVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.smm.entity.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.util.Date;


public class JWTUtil {
    private static final int EXPIRE_TIME = 5*60*1000;
    private final static Logger log = LoggerFactory.getLogger(JWTUtil.class);
    public static String createToken(User user){
        Date date = new Date(System.currentTimeMillis()+EXPIRE_TIME);
        //PrivateKey privateKey = new PrivateKey();
        //JwkProvider jwkProvider = new UrlJwkProvider("localhost.com");
        //Jwk jwk = jwkProvider.get("sha");
        //RSAPublicKey publicKey = (RSAPublicKey) jwk.getPublicKey();
        //RSAPrivateKey privateKey = jwk.get
        Algorithm algorithm = Algorithm.HMAC256("SECRET");
        return JWT.create()
                .withClaim("username", user.getUsername())
                .withExpiresAt(date)
                .sign(algorithm);

    }

}
